<?php namespace Common\Model;
use Hdphp\Model\Model;

class User extends Model{
	protected $table = "360mall_admin";
	protected $validate = array(
	  array("a_name","required","请输入用户名",3,3),
	   array("a_pwd","required","请输入密码",3,3),
	);
	protected $auto = array(
	  array("a_logintime","time","function",3,3),
	 
	);
	public function login(){
		if(!$this->create()) return false;
	    $account = $_POST['a_name'];
		$pwd = md5($_POST['a_pwd']);
		$data = $this->where("a_name","$account")->first();
		if(!$data){
			$this->error = "用户名不存在";
			return false;
		}
		if($pwd!=$data['a_pwd']){
			$this->error = "密码不正确";
			return false;
		}
		if($data['a_islock']==1){
			$this->error = "账户已被锁定";
			return false;
		}
		$ip = Request::ip();
		$this->update(array("a_logintime"=>time(),"a_ip"=>"$ip"));
		//走到这里说明用户名密码都正确
		$_SESSION['aid'] = $data['a_id'];
		return true;
		
	}
}

